using System;
using System.Linq;
using System.Data;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using Widgetsphere.Core.DataAccess;
using Widgetsphere.Core.Util;
using Widgetsphere.Core.Logging;
using Widgetsphere.Core.Exceptions;
using ACME.Northwind.Business;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Business.Rules;
using ACME.Northwind.Business.SelectCommands;
using System.IO;
using System.Data.SqlClient;

namespace ACME.Northwind.Domain.Objects
{
	#region internal class
	/// <summary>
	/// This is an customizable extender for the domain class associated with the 'Employee' object collection
	/// </summary>
	[Serializable()]
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	partial class DomainEmployeeCollection : PersistableDomainCollectionBase, IEnumerable, ISerializable, IDisposable
	{
		#region Member Variables

		//Generated Relationships This Object Plays Parent Role
		internal bool EmployeeFilled = false;
		internal bool EmployeeTerritoryFilled = false;
		internal bool OrderFilled = false;


		#endregion

		#region ISerializable Members
		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected DomainEmployeeCollection(SerializationInfo info, StreamingContext context):this()
		{
			EmployeeTerritoryFilled = (bool)info.GetValue("EmployeeTerritoryFilled", typeof(bool));
			OrderFilled = (bool)info.GetValue("OrderFilled", typeof(bool));

		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("EmployeeTerritoryFilled", EmployeeTerritoryFilled);
			info.AddValue("OrderFilled", OrderFilled);

		}
		#endregion

		#region Properties

		internal SubDomain SubDomain
		{
			get{ return (SubDomain)this.DataSet; }
		}

		internal string Modifier
		{
			get{ return SubDomain.Modifier; }
		}

		internal virtual DataRelation EmployeeEmployeeTerritoryRelation
		{
			get
			{
				if(!this.EmployeeTerritoryFilled)
				{
					EmployeeTerritorySelectByEmployeePks retrieveRule = new EmployeeTerritorySelectByEmployeePks();
					this.SubDomain.AddSelectCommand(retrieveRule);
					this.SubDomain.RunSelectCommands();
				}
				return this.SubDomain.Relations["EmployeeEmployeeTerritoryRelation"];
			}
		}

		internal virtual DataRelation EmployeeOrderRelation
		{
			get
			{
				if(!this.OrderFilled)
				{
					OrderSelectByEmployeePks retrieveRule = new OrderSelectByEmployeePks();
					this.SubDomain.AddSelectCommand(retrieveRule);
					this.SubDomain.RunSelectCommands();
				}
				return this.SubDomain.Relations["EmployeeOrderRelation"];
			}
		}

		//Generate Property Access To Related Tables
		internal virtual DomainEmployeeTerritoryCollection RelatedEmployeeTerritoryCollection
		{
			get { return (DomainEmployeeTerritoryCollection)this.SubDomain.GetDomainCollection(Collections.EmployeeTerritoryCollection); }
		}

		internal virtual DomainOrderCollection RelatedOrderCollection
		{
			get { return (DomainOrderCollection)this.SubDomain.GetDomainCollection(Collections.OrderCollection); }
		}

		//Generated Domain Properties Where This Object Plays Both Roles
		//

		#endregion

		#region Contructors /Initialization

		internal DomainEmployeeCollection()
		{
			try
			{
				base.TableName = "EmployeeCollection";
				this.InitClass();
			}
			catch (System.Data.DBConcurrencyException dbcex) { throw new ConcurrencyException(GlobalValues.ERROR_CONCURRENCY_FAILURE, dbcex); }
			catch (System.Data.SqlClient.SqlException sqlexp) { if (sqlexp.Number == 547 || sqlexp.Number == 2627) throw new UniqueConstraintViolatedException(GlobalValues.ERROR_CONSTRAINT_FAILURE, sqlexp); else throw; }
			catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); throw; }
		}

		private void InitClass() 
		{
			BeginInit();
			this.columnTitleOfCourtesy = new DataColumn("TitleOfCourtesy", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnTitleOfCourtesy);
			this.columnTitleOfCourtesy.Caption = "";
			this.columnTitle = new DataColumn("Title", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnTitle);
			this.columnTitle.Caption = "";
			this.columnReportsTo = new DataColumn("ReportsTo", typeof(int), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnReportsTo);
			this.columnReportsTo.Caption = "";
			this.columnRegion = new DataColumn("Region", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnRegion);
			this.columnRegion.Caption = "";
			this.columnPostalCode = new DataColumn("PostalCode", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnPostalCode);
			this.columnPostalCode.Caption = "";
			this.columnPhotoPath = new DataColumn("PhotoPath", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnPhotoPath);
			this.columnPhotoPath.Caption = "";
			this.columnPhoto = new DataColumn("Photo", typeof(System.Byte[]), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnPhoto);
			this.columnPhoto.Caption = "";
			this.columnNotes = new DataColumn("Notes", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnNotes);
			this.columnNotes.Caption = "";
			this.columnLastName = new DataColumn("LastName", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnLastName);
			this.columnLastName.AllowDBNull = false;
			this.columnLastName.DefaultValue = "";
			this.columnLastName.Caption = "";
			this.columnHomePhone = new DataColumn("HomePhone", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnHomePhone);
			this.columnHomePhone.Caption = "";
			this.columnHireDate = new DataColumn("HireDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnHireDate);
			this.columnHireDate.Caption = "";
			this.columnFirstName = new DataColumn("FirstName", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnFirstName);
			this.columnFirstName.AllowDBNull = false;
			this.columnFirstName.DefaultValue = "";
			this.columnFirstName.Caption = "";
			this.columnExtension = new DataColumn("Extension", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnExtension);
			this.columnExtension.Caption = "";
			this.columnEmployeeId = new DataColumn("EmployeeID", typeof(int), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnEmployeeId);
			this.columnEmployeeId.AllowDBNull = false;
			this.columnEmployeeId.AutoIncrement = true;
			this.columnEmployeeId.AutoIncrementSeed = -1;
			this.columnEmployeeId.AutoIncrementStep = -1;
			this.columnEmployeeId.Caption = "";
			this.columnCountry = new DataColumn("Country", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCountry);
			this.columnCountry.Caption = "";
			this.columnCity = new DataColumn("City", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCity);
			this.columnCity.Caption = "";
			this.columnBirthDate = new DataColumn("BirthDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnBirthDate);
			this.columnBirthDate.Caption = "";
			this.columnAddress = new DataColumn("Address", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnAddress);
			this.columnAddress.Caption = "";
			this.columnModifiedBy = new DataColumn("ModifiedBy", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnModifiedBy);
			this.columnModifiedDate = new DataColumn("ModifiedDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnModifiedDate);
			this.columnCreatedBy = new DataColumn("CreatedBy", typeof(string), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCreatedBy);
			this.columnCreatedDate = new DataColumn("CreatedDate", typeof(DateTime), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnCreatedDate);
			this.columnTimeStamp = new DataColumn("TimeStamp", typeof(System.Byte[]), null, System.Data.MappingType.Element);
			base.Columns.Add(this.columnTimeStamp);
			base.Constraints.Add(new UniqueConstraint("PrimaryKey", new DataColumn[] {this.columnEmployeeId}, true));
			EndInit();
		}

		private bool mModifyUpdateOn = true;

		/// <summary>
		/// Raises the RowChanged event.
		/// </summary>
		protected override void OnRowChanged(DataRowChangeEventArgs e)
		{
			base.OnRowChanged(e);
			if(e.Action == DataRowAction.Change && mModifyUpdateOn)
			{
				mModifyUpdateOn = false;
				if ((e.Row[this.ModifiedByColumn] == System.DBNull.Value) || ((string)e.Row[this.ModifiedByColumn] != this.Modifier)) e.Row[this.ModifiedByColumn] = this.Modifier;
				mModifyUpdateOn = true;
			}
		}

		#endregion

		#region Database Retrieval

		internal DomainEmployee NewItem()
		{
			DomainEmployee retval = (DomainEmployee)(base.NewRow());
			((DataRow)retval)[ModifiedByColumn] = this.Modifier;
			((DataRow)retval)[ModifiedDateColumn] = DateTime.Now;
			((DataRow)retval)[CreatedByColumn] = this.Modifier;
			((DataRow)retval)[CreatedDateColumn] = DateTime.Now;

			return retval;
		}

		internal DomainEmployee NewItem(int employeeid)
		{
			DomainEmployee retval = (DomainEmployee)(base.NewRow());
			((DataRow)retval)["EmployeeID"] = employeeid;
			((DataRow)retval)[ModifiedByColumn] = this.Modifier;
			((DataRow)retval)[ModifiedDateColumn] = DateTime.Now;
			((DataRow)retval)[CreatedByColumn] = this.Modifier;
			((DataRow)retval)[CreatedDateColumn] = DateTime.Now;

			return retval;
		}

		internal void AddItem(DomainEmployee item)
		{
			base.Rows.Add(item);
		}

		internal void InsertAtEmployee(DomainEmployee item, int pos)
		{
			base.Rows.InsertAt(item, pos);
		}

		internal virtual void Persist()
		{
			this.SubDomain.Persist();
		}

		#region Select Methods

		internal static DomainEmployeeCollection RunSelect(EmployeeSearch search, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new EmployeeSelectBySearch(search));
			sd.RunSelectCommands();
			return (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
		}

		internal static DomainEmployeeCollection RunSelect(EmployeeSearch search, EmployeePaging paging, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			EmployeeSelectBySearch command = new EmployeeSelectBySearch(search, paging);
			sd.AddSelectCommand(command);
			sd.RunSelectCommands();
			paging.RecordCount = command.Count;
			return (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
		}

		internal static DomainEmployeeCollection RunSelect(string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new EmployeeSelectAll());
			sd.RunSelectCommands();
			return (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
		}

		internal static DomainEmployeeCollection RunSelect(int page, int pageSize, string orderByColumn, bool ascending, string filter, out int count, string modifier)
		{
			DomainEmployeeCollection returnVal = null;
			SubDomain sd = new SubDomain(modifier);
			EmployeePagedSelect retrieveRule = new EmployeePagedSelect(page, pageSize, PersistableDomainCollectionBase.DataColumnNameToParameterName(orderByColumn), ascending, filter);
			sd.AddSelectCommand(retrieveRule);
			sd.RunSelectCommands();
			returnVal = (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
			count = retrieveRule.Count;
			return returnVal;
		}

		internal static DomainEmployeeCollection SelectByEmployeePks(List<EmployeePrimaryKey> primaryKeys, string modifier)
		{
			SubDomain sd = new SubDomain(modifier);
			sd.AddSelectCommand(new EmployeeSelectByPks(primaryKeys));
			sd.RunSelectCommands();
			return (DomainEmployeeCollection)sd.GetDomainCollection(Collections.EmployeeCollection);
		}

		#endregion

		#endregion

		#region DomainEmployee Collection Methods
		internal void RemoveEmployee(DomainEmployee item) 
		{
			base.Rows.Remove(item);
		}

		internal virtual int Count 
		{
			get { return base.Rows.Count; }
		}

		/// <summary>
		/// Returns an enumerator that can be used to iterate through the collection.
		/// </summary>
		/// <returns>An Enumerator that can iterate through the objects in this collection.</returns>
		public virtual System.Collections.IEnumerator GetEnumerator() 
		{
			return base.Rows.GetEnumerator();
		}

		/// <summary>
		/// Gets or sets the element at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index of the element to get or set. </param>
		/// <returns>The element at the specified index.</returns>
		internal DomainEmployee this[int index] 
		{
			get { return ((DomainEmployee)(base.Rows[index])); }
		}

		internal DomainEmployee GetEmployee(int employeeid)
		{
			return ((DomainEmployee)(base.Rows.Find(new object[] {employeeid})));
		}

		#endregion

		#region Data Columns Setup
		protected DataColumn columnTitleOfCourtesy;
		protected DataColumn columnTitle;
		protected DataColumn columnReportsTo;
		protected DataColumn columnRegion;
		protected DataColumn columnPostalCode;
		protected DataColumn columnPhotoPath;
		protected DataColumn columnPhoto;
		protected DataColumn columnNotes;
		protected DataColumn columnLastName;
		protected DataColumn columnHomePhone;
		protected DataColumn columnHireDate;
		protected DataColumn columnFirstName;
		protected DataColumn columnExtension;
		protected DataColumn columnEmployeeId;
		protected DataColumn columnCountry;
		protected DataColumn columnCity;
		protected DataColumn columnBirthDate;
		protected DataColumn columnAddress;
		protected DataColumn columnCreatedBy;
		protected DataColumn columnCreatedDate;
		protected DataColumn columnModifiedBy;
		protected DataColumn columnModifiedDate;
		protected DataColumn columnTimeStamp;
		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn TitleOfCourtesyColumn 
		{
			get { return this.columnTitleOfCourtesy; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn TitleColumn 
		{
			get { return this.columnTitle; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ReportsToColumn 
		{
			get { return this.columnReportsTo; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn RegionColumn 
		{
			get { return this.columnRegion; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn PostalCodeColumn 
		{
			get { return this.columnPostalCode; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn PhotoPathColumn 
		{
			get { return this.columnPhotoPath; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn PhotoColumn 
		{
			get { return this.columnPhoto; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn NotesColumn 
		{
			get { return this.columnNotes; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn LastNameColumn 
		{
			get { return this.columnLastName; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn HomePhoneColumn 
		{
			get { return this.columnHomePhone; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn HireDateColumn 
		{
			get { return this.columnHireDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn FirstNameColumn 
		{
			get { return this.columnFirstName; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn ExtensionColumn 
		{
			get { return this.columnExtension; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn EmployeeIdColumn 
		{
			get { return this.columnEmployeeId; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn CountryColumn 
		{
			get { return this.columnCountry; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn CityColumn 
		{
			get { return this.columnCity; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn BirthDateColumn 
		{
			get { return this.columnBirthDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting("", false, 0)]
		public DataColumn AddressColumn 
		{
			get { return this.columnAddress; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn ModifiedDateColumn 
		{
			get { return this.columnModifiedDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn ModifiedByColumn 
		{
			get { return this.columnModifiedBy; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn CreatedDateColumn 
		{
			get { return this.columnCreatedDate; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn CreatedByColumn 
		{
			get { return this.columnCreatedBy; }
		}

		[Widgetsphere.Core.Attributes.DataSetting(false)]
		public DataColumn TimeStampColumn 
		{
			get { return this.columnTimeStamp; }
		}

		#endregion

		#region Protected Overrides

		/// <summary>
		/// Create a new instance of this object type
		/// </summary>
		protected override DataTable CreateInstance()
		{
			return new DomainEmployeeCollection();
		}

		/// <summary>
		/// Create new row from a DataRowBuilder
		/// </summary>
		/// <param name="builder">The DataRowBuilder object that is used to create the new row</param>
		/// <returns>A new datarow of type 'Employee'</returns>
		protected override DataRow NewRowFromBuilder(DataRowBuilder builder)
		{
			DomainEmployee retval = new DomainEmployee(builder);
			return retval;
		}

		/// <summary>
		/// Returns the type of the datarow that this collection holds
		/// </summary>
		protected override System.Type GetRowType() 
		{
			return typeof(DomainEmployee);
		}
		#endregion

		#region Implement Persistable Table Abstact Methods

		/// <summary>
		/// Gets a list of parameters for SQL update commands.
		/// </summary>
		protected override List<IDbDataParameter> GetUpdateFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Gets a list of parameters for SQL insert commands.
		/// </summary>
		protected override List<IDbDataParameter> GetInsertFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Gets a list of parameters for SQL delete commands.
		/// </summary>
		protected override List<IDbDataParameter> GetDeleteFreeSqlParameters()
		{
			return null;
		}

		/// <summary>
		/// Determines if the stored procedure or SQL text is used for CRUD operations.
		/// </summary>
		protected override bool UseStoredProcedure
		{
			get { return true; }
		}

		/// <summary>
		/// The stored procedure name that performs deletes for the objects in this collection
		/// </summary>
		protected override string DeleteStoredProcedureName
		{
			get { return "gen_EmployeeDelete"; }
		}

		/// <summary>
		/// The SQL that performs deletes for the objects in this collection
		/// </summary>
		protected override string DeleteSQLText
		{
			get { return null; }
		}

		/// <summary>
		/// The stored procedure name that performs inserts for the objects in this collection
		/// </summary>
		protected override string InsertStoredProcedureName
		{
			get { return "gen_EmployeeInsert"; }
		}

		/// <summary>
		/// The SQL that performs inserts for the objects in this collection
		/// </summary>
		protected override string InsertSQLText
		{
			get { return null; }
		}

		/// <summary>
		/// The stored procedure name that performs updates for the objects in this collection
		/// </summary>
		protected override string UpdateStoredProcedureName
		{
			get { return "gen_EmployeeUpdate"; }
		}

		/// <summary>
		/// The SQL that performs updates for the objects in this collection
		/// </summary>
		protected override string UpdateSQLText
		{
			get { return null; }
		}

		public override void SetChildSelectedFalse()
		{
			EmployeeTerritoryFilled = false;
			OrderFilled = false;
		}

		/// <summary>
		/// Creates the referential integrity for this collection
		/// </summary>
		public override void CreateRelations()
		{
			if(!SubDomain.Relations.Contains("EmployeeEmployeeTerritoryRelation"))
			{
				if(SubDomain.Contains(Collections.EmployeeTerritoryCollection))
				{
					DataRelation employeeEmployeeTerritoryRelation = new DataRelation("EmployeeEmployeeTerritoryRelation",new DataColumn[]{EmployeeIdColumn}, new DataColumn[]{RelatedEmployeeTerritoryCollection.EmployeeIdColumn});
					SubDomain.Relations.Add(employeeEmployeeTerritoryRelation);
				}
			}

			if(!SubDomain.Relations.Contains("EmployeeOrderRelation"))
			{
				if(SubDomain.Contains(Collections.OrderCollection))
				{
					DataRelation employeeOrderRelation = new DataRelation("EmployeeOrderRelation",new DataColumn[]{EmployeeIdColumn}, new DataColumn[]{RelatedOrderCollection.EmployeeIdColumn});
					SubDomain.Relations.Add(employeeOrderRelation);
				}
			}

			//Generated Relationships This Object Plays Both Roles

			//TO DO: 
			//Parent Employee
			//Child Employee
			//Role  

		}

		bool _handlingError = false;
		/// <summary>
		/// Determines if errors are handled by this object
		/// </summary>
		public override bool HandleErrors()
		{
			if (_handlingError) return false;
			_handlingError = true;
			try
			{
			DataRow[] rowsInError = this.GetErrors();

			foreach(DomainEmployee item in rowsInError)
			{
				item.ClearErrors();
			}
			bool handledError = false;

			return handledError;
			}
			catch
			{
				throw;
			}
			finally
			{
				_handlingError = false;
			}
		}
		#endregion 

		#region Helper Methods

		internal virtual string GetPrimaryKeyXml()
		{
			return GetPrimaryKeyXml(((IEnumerable<ACME.Northwind.Business.Objects.Employee>)new ACME.Northwind.Business.Objects.EmployeeCollection(this)).Select(x => x.PrimaryKey));
		}

		internal static string GetPrimaryKeyXml(ACME.Northwind.Business.Objects.EmployeePrimaryKey primaryKey)
		{
			List<ACME.Northwind.Business.Objects.EmployeePrimaryKey> list = new List<ACME.Northwind.Business.Objects.EmployeePrimaryKey>();
			list.Add(primaryKey);
			return GetPrimaryKeyXml(new List<ACME.Northwind.Business.Objects.EmployeePrimaryKey>(list));
		}

		internal static string GetPrimaryKeyXml(IEnumerable<ACME.Northwind.Business.Objects.EmployeePrimaryKey> primaryList)
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("EmployeesList");
			foreach(ACME.Northwind.Business.Objects.EmployeePrimaryKey primaryKey in primaryList)
			{
				xWriter.WriteStartElement("Employees");
				xWriter.WriteStartElement("EmployeeID");
				xWriter.WriteString(primaryKey.EmployeeId.ToString());
				xWriter.WriteEndElement();
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}


		private string GetEmployeeForeignKeyXml()
		{
			StringWriter sWriter = new StringWriter();
			XmlTextWriter xWriter = new XmlTextWriter(sWriter);
			xWriter.WriteStartDocument();
			xWriter.WriteStartElement("EmployeesList");
			foreach(DomainEmployee employee in this)
			{
				xWriter.WriteStartElement("Employees");
				if(employee.ReportsTo != null)
				{
					xWriter.WriteStartElement("EmployeeID");
					xWriter.WriteString(employee.ReportsTo.ToString());
					xWriter.WriteEndElement();
				}
				xWriter.WriteEndElement();
			}
			xWriter.WriteEndElement();
			xWriter.WriteEndDocument();
			xWriter.Flush();
			xWriter.Close();
			return sWriter.ToString();
		}

		#endregion

		#region Methods

		#endregion

		#region IDisposable Members

		void IDisposable.Dispose()
		{
		}

		#endregion

	}
	#endregion

}
